package de.baumann.browser.activitys

import android.content.Intent
import android.support.v4.view.PagerAdapter
import android.support.v4.view.ViewPager
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import de.baumann.browser.R
import de.baumann.browser.base.BaseOdinActivity
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.IBaseView
import de.baumann.browser.utils.put
import de.baumann.browser.utils.save
import kotlinx.android.synthetic.main.activity_guide.*


class GuideActivity : BaseOdinActivity<IBaseView, BasePresenter<IBaseView>>() {

    override fun createPresenter(): BasePresenter<IBaseView>? {
        return null
    }

    override fun createView(): IBaseView? {
        return null
    }

    //    lateinit var vpGuide: ViewPager
    lateinit var mIvList: ArrayList<View>
    private val drawables = listOf(R.drawable.bg_guide_1,
            R.drawable.bg_guide_2,
            R.drawable.bg_guide_3)


    override fun getLayout(): Int {
        return R.layout.activity_guide
    }

    override fun initView() {

        ivExperience.setOnClickListener {
            put("guide", true)
            startActivity(Intent(mContext, MainActivity::class.java))
            finish()
        }

        vpGuide.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrollStateChanged(state: Int) {

            }

            override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
            }

            override fun onPageSelected(position: Int) {

                if (position == 2) {
                    ivExperience.visibility = View.VISIBLE
                } else {
                    ivExperience.visibility = View.GONE
                }
            }
        })
    }

    override fun initData() {
        mIvList = ArrayList()
        for (i in 0..2) {
            val imageView = ImageView(mContext)
            imageView.setImageResource(drawables[i])
            imageView.scaleType = ImageView.ScaleType.CENTER_CROP
            mIvList.add(imageView)
        }
        vpGuide.adapter = pageAdapter
    }

    var pageAdapter = object : PagerAdapter() {

        override fun isViewFromObject(view: View, `object`: Any): Boolean {
            return view == `object`
        }

        override fun getCount(): Int {
            return mIvList.size
        }

        override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
            container.removeView(mIvList[position])
        }

        override fun instantiateItem(container: ViewGroup, position: Int): Any {
            container.addView(mIvList[position])
            return mIvList[position]
        }
    }

    override fun showBindEth(): Boolean {
        return false
    }
}
